package cn.stylefeng.guns.modular.bms.controller;

import cn.stylefeng.guns.base.pojo.node.ZTreeNode;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bms.entity.BmsWelfare;
import cn.stylefeng.guns.modular.bms.model.params.BmsWelfareParam;
import cn.stylefeng.guns.modular.bms.service.BmsWelfareService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 福利信息表控制器
 *
 * @author yzb
 * @Date 2021-03-22 23:27:17
 */
@Controller
@RequestMapping("/bmsWelfare")
public class BmsWelfareController extends BaseController {

    private String PREFIX = "/bms/bmsWelfare";

    @Autowired
    private BmsWelfareService bmsWelfareService;

    /**
     * 跳转到主页面
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/bmsWelfare.html";
    }

    /**
     * 新增页面
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/bmsWelfare_add.html";
    }

    /**
     * 编辑页面
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/bmsWelfare_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BmsWelfareParam bmsWelfareParam) {
        this.bmsWelfareService.add(bmsWelfareParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BmsWelfareParam bmsWelfareParam) {
        this.bmsWelfareService.update(bmsWelfareParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BmsWelfareParam bmsWelfareParam) {
        this.bmsWelfareService.delete(bmsWelfareParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BmsWelfareParam bmsWelfareParam) {
        BmsWelfare detail = this.bmsWelfareService.getById(bmsWelfareParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BmsWelfareParam bmsWelfareParam) {
        return this.bmsWelfareService.findPageBySpec(bmsWelfareParam);
    }


    /**
     * 获取树状列表
     *
     */
    @ResponseBody
    @RequestMapping(value = "/welfareTreeList")
    public List<ZTreeNode> welfareTreeList() {
        List<ZTreeNode> postTreeList = this.bmsWelfareService.welfareTreeList();
        postTreeList.add(ZTreeNode.createParent());
        return postTreeList;
    }

}


